package com.sky.rabbit.producer.web;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("rabbitProducer")
public class RabbitMQProducerController {

    @Autowired
    private AmqpTemplate rabbitTemplate;


    @GetMapping("sendDirect")
    public void sendDirect(){
        for(int i = 0 ; i <= 10; i++) {
            String context = "hello " + new Date();
            System.out.println("Sender : " + context + i);
            //this.rabbitTemplate.convertAndSend("direct", "directKey1", context);
            //this.rabbitTemplate.convertAndSend("topic", "topicKey1", context);
            this.rabbitTemplate.convertAndSend("sky", context + "=== sky" + "=====" + i);
            this.rabbitTemplate.convertAndSend("name", context + "=== name" + "=====" + i);
            this.rabbitTemplate.convertAndSend("hct", context + "=== hct" + "=====" + i);

            rabbitTemplate.convertAndSend("skyExchange", "topic.sky.name", context + "=== topicChange" + "=====" + i);
            this.rabbitTemplate.convertAndSend("skyTopicExchange", "sky.topic.hct.sz", context + "=== topicChange1" + "=====" + i);
            this.rabbitTemplate.convertAndSend("skyDirectExchange", "direct.sky.hct", context + "=== directChange" + "=====" + i);
        }
    }

    @GetMapping("sendTopic")
    public void sendTopic(){
        String context = "发送当前时间： " + new Date();
        rabbitTemplate.convertAndSend("skyExchange", "topic.sky.name", context);
    }
}
